package com.zlm.user.emp.controller;

import com.zlm.common.base.BaseController;
import com.zlm.common.constants.CodeConstants;
import com.zlm.common.dto.JsonResultDto;
import com.zlm.common.entity.EmpUserExperienceDO;
import com.zlm.user.emp.service.EmpUserExperienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: duyufu
 * @Date: 2019/5/15 9:37
 */
@RestController
@RequestMapping(value = "/empUserExperience")
public class EmpUserExperienceController extends BaseController {

    @Autowired
    private EmpUserExperienceService empUserExperienceService;

    @PostMapping("/saveUserExperience")
    public JsonResultDto saveUserExperience(@RequestBody EmpUserExperienceDO empUserExperienceDO) {
        try {
            if (null == empUserExperienceDO.getEid()) {
                //新增工作经验
                empUserExperienceService.insertUserExperience(empUserExperienceDO);
            } else {
                empUserExperienceService.updateUserExperience(empUserExperienceDO);
            }
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return fail(CodeConstants.CODE_BUSY);
        }
    }

    /**
     * 删除工作经历
     * @param empId
     * @param eid
     * @return
     */
    @GetMapping("/deleteUserExperience")
    public JsonResultDto deleteUserExperience(Integer empId, Integer eid) {
        try {
            empUserExperienceService.deleteUserExperience(empId,eid);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return fail(CodeConstants.CODE_BUSY);
        }
    }

    /**
     * 获取工作经历
     * @param empId
     * @return
     */
    @GetMapping("/queryUserExperience")
    public JsonResultDto queryUserExperience(Integer empId) {
        try {
            List<EmpUserExperienceDO> experienceList = empUserExperienceService.queryUserExperience(empId);
            return success(experienceList);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(CodeConstants.CODE_BUSY);
        }
    }
}
